package com.wandong.cinema.util;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LogUtil {
    private static final String LOG_FILE = "cinema_log.txt";
    private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    // 记录日志（含时间、操作内容）
    public static void log(String content) {
        try (PrintWriter out = new PrintWriter(new FileWriter(LOG_FILE, true))) {
            String log = "[" + SDF.format(new Date()) + "] " + content;
            out.println(log);
            System.out.println(log); // 同时打印到控制台
        } catch (IOException e) {
            System.err.println("日志记录失败: " + e.getMessage());
        }
    }
}
